/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswe.solestac.entity;

import java.util.List;
import org.colswe.solestac.view.Principal;

/**
 *
 * @author Edison Parra
 */
public final class ActualUser {
    
    /**The instance of the object.
     */
    private static ActualUser instance;
    /**Username of the Actual User.
     */
    private String username;
    /**Role of the Actual USer.
     */
    private String role;
    /**List of permissions of the Actual User.
     */
    private List<Permission> permissions;
    /**The object assigned to the GUI for the Actual User.
     */
    private Principal principal;
    /**Id of the Actual User.
     */
    private long id;
    

    /** Getter for Principal.
     * @return The Principal object.
     */
    public Principal getPrincipal() {
        return principal;
    }

    /**Setter for Principal.
     * @param newPrincipal The new object
     */
    public void setPrincipal(final Principal newPrincipal) {
        this.principal = newPrincipal;
    }

    /**Private default constructor.
     */
    private ActualUser() {
    }

    /**Getter for the instance.
     * @return THe actual and unique instance of the Actual User,
     */
    public static synchronized ActualUser getInstance(){
        if (instance == null) {
            instance = new ActualUser();
        }
	return instance;
    }

    /**Setter for the instance.
     * @param un The username.
     * @param r The role.
     * @param perm The permissions list.
     * @param newId The Id.
     */
    public void setInstance(final String un, final String r, final List<Permission> perm, final long newId) {
        instance.username = un;
        instance.role = r;
        instance.permissions = perm;
        instance.id = newId;
        
    }

    /**Set the instance in null. In the logout process.
     */
    public void setNull() {
        instance = null;
    }

    /**Getter for role.
     * @return The role value.
     */
    public String getRole() {
        return instance.role;
    }

    /**Getter for permissions.
     * @return The permissions list.
     */
    public List<Permission> getPermissions(){
        return instance.permissions;
    }

    /**Getter for Id.
     * @return The Id value
     */
    public long getId() {
        return id;
    }

    /**Setter for Id.
     * @param newId The new value
     */
    public void setId(final long newId) {
        this.id = newId;
    }

    /**Getter for Username.
     * @return The username value.
     */
    public String getUsername() {
        return username;
    }

    /**Setter for Username.
     * @param newUsername The new value
     */
    public void setUsername(final String newUsername) {
        this.username = newUsername;
    }
    
    /**Compares an user with a logged user.
     * @param otherUsername The username to compare.
     * @param otherId The id to compare.
     * @return The result of the comparison.
     */
    public boolean sameUser(final String otherUsername, final long otherId) {
        return (otherId == this.id && otherUsername.equals(this.username) );
    }
    
}
